package com.ds.infra.rpc.core.loadbalance;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 负载均衡工厂
 *
 * @author WeiShaoying
 */
// 默认实现（可扩展为从配置读取策略）
public class DefaultLoadBalanceFactory implements LoadBalanceFactory {

    private final Map<String, LoadBalance> strategyMap = new ConcurrentHashMap<>();

    @Override
    public LoadBalance getLoadBalance(String serviceName) {
        return strategyMap.computeIfAbsent(serviceName, k -> {
            // 默认策略，可从配置读取每个服务的策略
            return new RoundRobinLoadBalance();
        });
    }
}
